package main

import (
	"HelloService/proto"
	"context"
	"fmt"
	"google.golang.org/grpc"

	"net"
)

type Server struct {
	proto.UnimplementedGreeterServer
}

func (svc *Server) mustEmbedUnimplementedGreeterServer() {
	panic("implement me")
}

// SayHello Hello ctx 处理协程超时
func (svc *Server) SayHello(ctx context.Context, request *proto.HelloRequest) (*proto.HelloReply, error) {
	fmt.Println(request.Name)
	return &proto.HelloReply{Message: "Hello " + request.Name}, nil
}

// 服务端
func main() {
	g := grpc.NewServer()
	proto.RegisterGreeterServer(g, &Server{})
	listen, err := net.Listen("tcp", "localhost:8080")
	if err != nil {
		panic("failed to listen:" + err.Error())
	}
	//保证客户端多次访问
	err = g.Serve(listen)
	if err != nil {
		panic("failed to start grpc:" + err.Error())
	}
}
